#ifndef FiniteStateMachine_H
#define FiniteStateMachine_H

#include <vector>
#include <stdio.h>
#include <iostream>
#include <irrKlang.h>
#include <GL\glut.h>
#include "MyMath.h"
#include "Vector3.h"
#include "Texture.h"
#include "Mouse.h"
#include "Camera.h"
#include "Unit.h"
#include "Range.h"
#include "Melee.h"
#include "MsgBoard.h"

class FSM
{
private:
	static FSM *Instance;

	bool myKeys[255];
	theMouseInfo mouseInfo;

	Camera *cam;
	Vector3D theCameraPosition;
	Vector3D theCameraDirection;
	float angle;
	bool toggle;
	bool msgboard;

	Texture floor[1];

	//  The number of frames
	int frameCount;
	//  Number of frames per second
	float fps;
	//  currentTime - previousTime is the time elapsed
	//  between every call of the Idle function
	int currentTime, previousTime;
	//  Pointer to a font style..
	//  Fonts supported by GLUT are: GLUT_BITMAP_8_BY_13, 
	//  GLUT_BITMAP_9_BY_15, GLUT_BITMAP_TIMES_ROMAN_10, 
	//  GLUT_BITMAP_TIMES_ROMAN_24, GLUT_BITMAP_HELVETICA_10,
	//  GLUT_BITMAP_HELVETICA_12, and GLUT_BITMAP_HELVETICA_18.
	//	GLvoid *font_style;
	void *font_style;
	
	// realtime loop control
	long timelastcall;
	// realtime loop control - frequency
	float frequency;

	bool LoadTGA(Texture *texture, char *filename);
	//  Draws a string at the specified coordinates.
	void printw(float x, float y, float z, char* format, ...);
	// Calculate the FPS
	void calculateFPS();
	// Display FPS
	void drawFPS();
	void DrawEnvironment();

	void DrawBackground();

	CUnit* FetchRangeUnit(int team);
	CUnit* FetchMeleeUnit(int team);
	void RenderUnit(CUnit*);
	void RenderLegend(int x, int y);
	void RenderControls(int x, int y);
	void SpawnNewRange(int team);
	void SpawnNewMelee(int team);
	void PrintMessages(void);
	void MessageBoardUpdate(CUnit *go_Unit);
	void MessageBoardPrint(void);

	std::vector<MessageBoard*> Msgb;

	std::vector<CUnit*> UnitList;

public:
	FSM();
	~FSM();

	static FSM *GetInstance();

	bool Init();
	void Exit();
	void Update();

	void renderScene(void);
	void changeSize(int w, int h);
	void inputKey(int key, int x, int y);
	void KeyboardDown(unsigned char key, int x, int y);
	void KeyboardUp(unsigned char key, int x, int y);
	void MouseMove(int x, int y);
	void MouseClick(int button, int state, int x, int y);
	std::vector<CUnit*>& GetUnitList(void);
};

#endif